/**
 * canvas实现文字换行
 * @param {}
 * @return
 */
export const drawtext = (ctx, t, x, y, w, lineheight = 20) => {
  // 参数说明
  // ctx：canvas的 2d 对象，t：绘制的文字，x,y:文字坐标，w：文字最大宽度
  const chr = t.split('');
  let temp = '';
  const row: any = [];

  for (let a = 0; a < chr.length; a++) {
    if (ctx.measureText(temp).width < w && ctx.measureText(temp + chr[a]).width <= w) {
      temp += chr[a];
    } else {
      row.push(temp);
      temp = chr[a];
    }
  }
  row.push(temp);
  for (let b = 0; b < row.length; b++) {
    ctx.fillText(row[b], x, y + (b + 1) * lineheight); // 每行字体y坐标间隔20
  }
};
